﻿using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Models;
using Estsh.Core.Controllers;

namespace Estsh.Core.Web.Areas.Wms.Controllers.NC
{
    [Route("wms/[controller]")]
    [ApiController]
    public class SplitCarrierController : WmsBaseController
    {
        private ISplitCarrierService service;

        // GET: SplitCarrierController
        public SplitCarrierController(ISplitCarrierService _service)
        {
            service = _service;
        }

        [HttpPost("GetCarrierByName")]
        public IActionResult GetCarrierByName(Newtonsoft.Json.Linq.JObject jobj)
        {
            string srcRackNo = jobj["srcRackNo"].ToString().Trim();
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.GetCarrierByName(srcRackNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("CheckStockByCartonNo")]
        public IActionResult CheckStockByCartonNo(Newtonsoft.Json.Linq.JObject jobj)
        {
            string srcRackNo = jobj["srcRackNo"].ToString().Trim();
            string cartonNo = jobj["cartonNo"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.CheckStockByCartonNo(srcRackNo, cartonNo,loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("CheckStockByCartonNoAndQty")]
        public IActionResult CheckStockByCartonNoAndQty(Newtonsoft.Json.Linq.JObject jobj)
        {
            string srcRackNo = jobj["srcRackNo"].ToString().Trim();
            string cartonNo = jobj["cartonNo"].ToString().Trim();
            string qty = jobj["qty"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.CheckStockByCartonNoAndQty(srcRackNo, cartonNo, qty, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("CheckStockByCartonNoAndQtyAddRackNo")]
        public IActionResult CheckStockByCartonNoAndQtyAddRackNo(Newtonsoft.Json.Linq.JObject jobj)
        {
            string srcRackNo = jobj["srcRackNo"].ToString().Trim();
            string cartonNo = jobj["cartonNo"].ToString().Trim();
            string qty = jobj["qty"].ToString().Trim();
            string destRackNo = jobj["destRackNo"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.CheckStockByCartonNoAndQtyAddRackNo(srcRackNo, cartonNo, qty, destRackNo, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }
       
    }
}
